window.workspace = function(){
	var response  = <?#$respons?>;
	var store, sm, grid, ngrid, nstore, container;
	var sid = {'id':Ext.id(), 'pid':Ext.id(), 'overid':Ext.id(),
		'status':Ext.id(), 'workflowid':Ext.id()};
 	store = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/workflow/monitor/dolist.html',
	    remoteSort	: true,
	    sortInfo	: {
            field		: 'id',
            direction	: 'DESC'
		},
		baseParams	: {
			start	: 0,
			limit	: main.pageSize
		},
		autoLoad		: true,
	    root			: 'dataset',
	 	totalProperty	: 'total',
	    fields			: ['id', 'workflowid', 'pid', 'stime', 'etime', 'status',
	    	'stopusername', 'stopuserid', 'stoptime', 'applyuserid', 'applyusername',
	    	'title', 'remark', 'overid']
	});
	sm   = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
 	grid = {
		xtype		: 'grid',
	    store		: store,
		region		: 'center', 
	    columns		: [
	    	sm,
			{header: 'ID编号',width:60,dataIndex:'id'},
			{header: '流程名称', width:120, dataIndex:'workflowid',renderer:function(val,obj,rec){
				return rec.get('title')+'['+val+']';
			}},
			{header: '开始执行时间', width:100, dataIndex:'stime'},
			{header: '完成时间', width:100, dataIndex:'etime'},
			{header: '执行状态', width:80, dataIndex:'status', renderer:function(v){
				return response.estatus[v];
			}},
			{header: '终止人员', width:140, dataIndex:'stopuserid', renderer:function(val,obj,rec){
				return ((val < 1)? '':rec.get('stopusername')+'-'+rec.get('stoptime'));
			}},
			{header: '申请人员', width:100, dataIndex:'applyuserid', renderer:function(val,obj,rec){
				return rec.get('applyusername')+'['+val+']';
			}},
			{header: '父流程ID', width:60, dataIndex:'pid'},
			{header: '总流程ID', width:60, dataIndex:'overid'}
		],
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
	    sm			: sm,
	    listeners 	:{'rowclick':function(grid, index, e){
		    	var rec = grid.getStore().getAt(index);
		    	nstore.baseParams.executionid  = rec.get('id');
		    	nstore.reload();
		    },'rowdblclick':function(grid, index, e){
		    	var id = grid.store.getAt(index).get('id');
	    		var url= '/admin/workflow/executor/id-xxx.html'.replace('xxx', id);
				window.open(url);
		    }
	    },
	    stripeRows	: true,
	    tbar		: [{
			text	: '刷新',
			iconCls	: 'icon-refresh',
			handler : function(){
					store.reload(); 
				}
			},'-',{
			text	: '终止',
			iconCls	: 'icon-stop',
			url     : '/admin/workflow/monitor/dostop.html',
			handler : function(){
					var rs = sm.getSelected();
					if(!rs) {
						Ext.Msg.alert('信息提示','请选择要终止的单据！');return;
					}
					Ext.Msg.prompt('信息提示','终止原因',function(btn, msg){
						if(btn == "ok") {
							msg = msg.trim();
							if(msg.length < 1) {
								Ext.Msg.alert('信息提示','请填写终止理由！');return;
							}
							Ext.Ajax.request({
								url		: '/admin/workflow/monitor/dostop.html',
								params 	: {'id':rs.get('id'),'remark':msg},
								success : function(resp, req){
									var data = Ext.decode(resp.responseText);
									Ext.Msg.alert('信息提示', data.msg);
									store.reload(); 
								}
							});
						}
					},window,true);
				}
			},'-','<b>检索资料：</b>','实例编号:',{
				xtype       : 'textfield',
				id	    	: sid.id,
				width	    : 60
			},'父实例编号:',{
				xtype       : 'textfield',
				id	    	: sid.pid,
				width	    : 60
			},'总实例编号:',{
				xtype       : 'textfield',
				id	    	: sid.overid,
				width	    : 60
			},'流程编号:',{
				xtype       : 'textfield',
				id	    	: sid.workflowid,
				width	    : 60
			},'状态:',{
				xtype		: 'combo',
				store		: new Ext.data.ArrayStore({
			        fields: ['id','name'],
			        data: main.cv2Array(response.estatus)
			    }),
				displayField	: 'name',
				valueField		: 'id',
				mode			: 'local',
				triggerAction	: 'all',
				emptyText		: '请选择',
				width			: 80,
				id  			: sid.status
			},'-',{
			text			: '检索',
			iconCls			: 'icon-search',
			handler: function() {
				store.baseParams.id        = Ext.getCmp(sid.id).getValue();
				store.baseParams.pid       = Ext.getCmp(sid.pid).getValue();
				store.baseParams.overid    = Ext.getCmp(sid.overid).getValue();
				store.baseParams.workflowid= Ext.getCmp(sid.workflowid).getValue();
				store.baseParams.status    = Ext.getCmp(sid.status).getValue();
				store.reload(); 
			}
		}],
		bbar		: new Ext.PagingToolbar({
			pageSize	: main.pageSize,
			store		: store,
			displayInfo	: true
		})
	};
 	nstore = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/workflow/monitor/donode.html',
	    baseParams	: {
			executionid	: 0
		},
		autoLoad	: true,
	    root		: 'dataset',
	    fields		: ['id', 'nodeid', 'preid', 'status', 'accepttime',
	    	'acceptuserid', 'completetime', 'result', 'acceptusername',
	    	'name', 'createtime', 'ccreceivers', 'expire', 'remark']
	});
 	ngrid = {
		xtype		: 'grid',
		title		: '处理详情',
		height		: 256,
	    store		: nstore,
	    split       : true,
		collapseMode: 'mini',
		bodyBorder  : false,
		animCollapse: true,
		autoScroll  : true,
		region		: 'south', 
	    columns		: [
			{header: 'ID编号',width:50,dataIndex:'id'},
			{header: '节点信息',width:100,dataIndex:'nodeid',renderer:function(val,obj,rec){
				return rec.get('name')+'['+val+']';
			}},
			{header: '前置节点',width:50,dataIndex:'preid'},
			{header: '状态', width:50, dataIndex:'status', renderer:function(v){
				return response.nstatus[v];
			}},
			{header: '节点解锁时间', width:100, dataIndex:'createtime'},
			{header: '在办用户', width:80, dataIndex:'acceptuserid',renderer:function(val,obj,rec){
				return ((val > 0)? rec.get('acceptusername'):'');
			}},
			{header: '接受时间', width:100, dataIndex:'accepttime'},
			{header: '完成时间', width:100, dataIndex:'completetime'},
			{header: '过期时间', width:100, dataIndex:'expire'},
			{header: '抄送给用户', width:100, dataIndex:'ccreceivers'},
			{header: '业务返回结果', width:80, dataIndex:'result'},
			{header: '备注', width:140, dataIndex:'remark'}
		],
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
	    stripeRows	: true,
	    tbar		: [{
			text	: '刷新',
			iconCls	: 'icon-refresh',
			handler : function(){
				nstore.reload(); 
				}
			}]
	};
	container = {
		layout		: 'border',
		region		: 'center',
		title		: response.title,
		items		: [grid, ngrid]
	}
	return container;
}();

